var portal = require('../controllers/portal-controller'),
    login  = require('../controllers/login-controller');

module.exports = function(app) {
    app.use(function*(next) {
        if (this.session.logined) {
            if (this.path === '/') {
                yield portal.portal;
            } else if (this.path === '/add') {
                yield portal.insert;
            } else {
                yield next;
            }
        } else if (this.path === '/login') {
            yield login.login;
        } else {
            yield login.portal;
        }
    });
};
